<%@page contentType="text/html;charset=UTF-8"%>
<%@taglib uri="/WEB-INF/tlds/framework.tld" prefix="framework"%>
<%@taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean"%>
<html>
<head>
<%@ include file="/common/inc/select.jsp" %>
<title>Tree selection</title>
</head>
<base target="_self">
<body>
<%
	String treeType = request.getParameter("treeType");
	String selectType = request.getParameter("selectType");
	String selectAll = request.getParameter("selectAll");
	String rootId = request.getParameter("rootId");
	String checkedId = request.getParameter("checkedId");
	String treeName = request.getParameter("treeName");
	String queryString = request.getParameter("queryString");
	String showParent = request.getParameter("showParent");
	String lazy = request.getParameter("lazy");

	if(rootId == null) rootId = "0";
	if(showParent == null) showParent = "";
%>

<div align="left" style="background:#EEEEEE;width:385px;height:320px;overflow:auto;border: 2 inset;padding:5pt;">
<framework:tree2 treeName="<%= treeName %>" serviceName="<%= treeType %>"
	rootId="<%= Long.parseLong(rootId) %>" checkedId="<%= checkedId %>"
	selectType="<%= selectType %>" selectAll="<%= "true".equalsIgnoreCase(selectAll) %>"
	lazy="<%= "true".equalsIgnoreCase(lazy) %>" queryString="<%= queryString %>"
/>
<center>

<input type="button" onclick="getSelected()"  class="savebutton" value='<bean:message key="form.ok" />'>
<input type="button" onclick="window.close()" class="savebutton" value='<bean:message key="form.cancel" />'>

<script>
	var showParent = "<%=showParent%>";
	function getParentNode(node){
		var text = new Array();
		getParentNodeText(node,text);
		var parentText = "";
		for(var i=0;i<text.length;i++){
			parentText = text[i] + "/"+parentText
		}
		return parentText;
	}
	function getParentNodeText(node,text){
		var parentNode = node.parentNode;
		if(parentNode!=null&&parentNode.value!=null){
			text[text.length++] = parentNode.text;
			getParentNodeText(parentNode,text);
		}
	}
	function getSelected(){
		var nodes = atree.getSelectedChildNodes();
		var retValue = "";
		for (var i = 0; i < nodes.length; i++) {
			if(showParent!=""){
				retValue += nodes[i].value+","+getParentNode(nodes[i])+nodes[i].text+";";	
			}else{
				retValue += nodes[i].value+","+nodes[i].text+";";	
			}	
		}
		if(retValue!=""){
			retValue = retValue.substring(0,retValue.length-1);
		}
		if(retValue == null || retValue == "") retValue = "0,0";
		window.returnValue = retValue;
		window.close();
	}
	
	function selectNode(){
		var selectType = "<%=selectType%>";
		
		if(selectType=="checkbox"){
			return;
		}
		var node = atree.getSelected();
		
		var value = node.value;
		if(value==null||value=="undefined"){
			return ;
		}
		if(showParent!=""){
			window.returnValue = node.value+","+getParentNode(node)+node.text;
		}else{
			window.returnValue = node.value+","+node.text;
		}
		window.close();
	}
	
	
</script>
</body>
</html>
